<%@page import="org.nutz.lang.Times"%>
<%@page import="java.util.List"%>
<%@page import="com.assic.utils.vo.Result"%>
<%@page import="com.assic.utils.vo.OperationState"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://ixion.net/tag/it" prefix="it"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String title = "";
	String key = "data";
	Map<String, Object> data = null;
	OperationState state = OperationState.DEFAULT;
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	Result result = (Result) request.getAttribute("obj");
	if (result != null) {
		title = result.getTitle();
		data = result.getData();
		state = result.getOperationState();
	}
	application.setAttribute("base", basePath);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=title%></title>
<link rel="shortcut icon" href="<%=basePath%>image/logo.ico">
<script src="<%=basePath%>js/jquery.js"></script>
<script src="<%=basePath%>js/receipt.js"></script>
<script src="<%=basePath%>js/jquery.autocomplete.min.js"></script>
<script src="<%=basePath%>bootstrap/js/bootstrap.min.js"></script>
<script src="<%=basePath%>jqdtp/jquery.datetimepicker.js"></script>
<!--[if lte IE 9]>
<script src="<%=basePath%>bootstrap/js/respond.min.js"></script>
<script src="<%=basePath%>bootstrap/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" src="<%=basePath%>js/lhgdialog.js?self=true&skin=iblack"></script>
<link href="<%=basePath%>bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="<%=basePath%>jqdtp/jquery.datetimepicker.css" rel="stylesheet">
<style type="text/css">
body {
	background-color: #EEE;
}

.addon-text {
	min-width: 125px;
}

.error {
	border-color: #F00;
}

.table {
	width: 98%;
	margin-left: 1%;
	margin-right: 1%;
	text-align: center;
}

thead {
	background-color: #ccc;
	text-align: center;
}

.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td,
	.table>tbody>tr>td, .table>tfoot>tr>td {
	padding: 8px;
	line-height: 1.42857143;
	vertical-align: middle;
}

caption {
	font-weight: 900;
	height: 34px;
}

.badge-ok {
	background-color: rgb(50, 184, 50);
	margin-right: 5px;
	min-width: 8px;
	height: 8px;
	border-radius: 4px;
	padding: 0
}

.badge-no {
	background-color: #ccc;
	margin-right: 5px;
	min-width: 8px;
	height: 8px;
	border-radius: 4px;
	padding: 0
}

.badge-tips {
	background-color: #f00;
	margin-right: 5px;
	min-width: 8px;
	height: 8px;
	border-radius: 4px;
	padding: 0
}

.badge-white {
	background-color: #FFF;
	margin-right: 5px;
	min-width: 8px;
	height: 8px;
	border-radius: 4px;
	padding: 0
}

.autocomplete-suggestions {
	border: 1px solid #999;
	background: #FFF;
	overflow: auto;
}

.autocomplete-suggestion {
	padding: 2px 5px;
	white-space: nowrap;
	overflow: hidden;
}

.autocomplete-selected {
	background: #F0F0F0;
}

.autocomplete-suggestions strong {
	font-weight: normal;
	color: #3399FF;
}

.table-n-p>thead>tr>th, .table>tbody>tr>th, .table-n-p>tfoot>tr>th,
	.table-n-p>thead>tr>td, .table-n-p>tbody>tr>td, .table-n-p>tfoot>tr>td
	{
	padding-left: 9px;
}

.error-info {
	background-color: #FFF;
	display: inline-block;
	float: right
}

i {
	cursor: pointer;
}
</style>
</head>
<body>
	<input type="hidden" id="opt_code" value='<%=data.get("optCode")%>'>
	<input type="hidden" id="r_Uid" value='<%=data.get("rUid")%>'>
	<input type="hidden" id="jqply__">
	<input type="hidden" id="syply__">
	<input type="hidden" id="sy_endTime">
	<input type="hidden" id="jq_endTime">
	<input type="hidden" id="vin">
	<input type="hidden" id="engine">
	<input type="hidden" id="model">
	<input type="hidden" id="cxdd_v_flag" value="1">
	<input type="hidden" id="ckdd_v_flag" value="1">
	<input type="hidden" id="timeOutFlag" value="0">
	<input type="hidden" id="timeOutReason">
	<input type="hidden" id="timeOutDescription">
	<input type="hidden" id="jd">
	<div id="sp_div"></div>
	<table id="main_table" class="table table-condensed  table-responsive table-bordered">
		<tr>
			<td style="width: 52%">
				<table class="table table-condensed  table-responsive table-bordered" style="width: 100%; margin: 0; padding: 0;">
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">报案电话</span> <input readonly="readonly" id="reportorNo" type="text" class="form-control" placeholder="报案人电话" check="true"
											reg="/^([1]([3][0-9]{1}|59|58|88|89)[0-9]{8})|((\d{7,8})|(\d{4}|d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/"
											d-value="" value='<%=data.get("phone")%>'>
									</div>
								</div>
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">报案人</span> <input onblur="replaceCont();" id="reportor" type="text" class="form-control" placeholder="报案人" check="true"
											reg="/^[\u4e00-\u9fa5]+$/" d-value="" value='<%=data.get("reportor")%>'>
									</div>
								</div>
							</div>
						</td>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">联系电话</span> <input id="contNo" type="text" class="form-control" placeholder="联系人电话" check="true"
											reg="/(^(\d{11})$|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/" d-value=""
											value='<%=data.get("phone")%>'>
									</div>
								</div>
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">联系人</span> <input id="cont" type="text" class="form-control" placeholder="联系人" check="true" reg="/^[\u4e00-\u9fa5]+$/"
											d-value="" value='<%=data.get("reportor")%>'>
									</div>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">车牌号码</span> <input id="plate" onblur="loadPlyInfo_();" type="text" class="form-control" placeholder="车牌号码后五位" check="true"
											reg="/^[\u4e00-\u9fa50-9A-Z]{6,11}$/" d-value="">
									</div>
								</div>
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">涉案车辆</span> <input id="sacl" onblur="updateSc();" type="text" class="form-control" placeholder="请输入涉案车辆数" value="2"
											check="true" reg="/^[1-9][\d]{0,3}$/" d-value=""><span class="input-group-addon">辆</span>
									</div>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group" title="请输入死亡人数">
										<span class="input-group-addon addon-text">死亡人数</span> <input id="dead" type="text" class="form-control" value="0" onblur="updateSc();" placeholder="死" check="true"
											reg="/^[\d]{1,4}$/" d-value="0"><span class="input-group-addon">人</span>
									</div>
									<!-- /input-group -->
								</div>
								<!-- /.col-lg-6 -->
								<div class="col-lg-6">
									<div class="input-group" title="请输入受伤人数">
										<span class="input-group-addon addon-text">受伤人数</span> <input id="injed" type="text" class="form-control" value="0" onblur="updateSc();" placeholder="伤" check="true"
											reg="/^[\d]{1,4}$/" d-value="0"><span class="input-group-addon">人</span>
									</div>
									<!-- /input-group -->
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group" style="max-width: 125px;">
										<span class="input-group-addon addon-text">物品损失</span><span class="input-group-addon" style="padding: 6px 0px; border-right: none;"> </span> <span
											class="input-group-addon"> <input type="checkbox" name="wp" id="wp" value="1" onclick="updateSc();">
										</span>
									</div>
								</div>
								<div class="col-lg-6">
									<div id="sc_div" class="input-group" style="max-width: 125px;" title="当前此选项不可选,已由涉案车辆数决定">
										<span class="input-group-addon addon-text">单车事故</span> <span class="input-group-addon" style="padding: 6px 0px; border-right: none;"> </span><span
											class="input-group-addon"> <input type="checkbox" name="sc" id="sc" value="1" disabled="disabled" onclick="updateCsState(this);">
										</span>
									</div>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group" style="max-width: 125px;">
										<span class="input-group-addon addon-text">代位求偿</span> <span class="input-group-addon" style="padding: 6px 0px; border-right: none;"> </span><span
											class="input-group-addon"> <input type="checkbox" name="dp" id="dp" value="1" onclick="jujdState(this);">
										</span>
									</div>
									<!-- div class="input-group" style="max-width: 125px;">
										<span class="input-group-addon addon-text">巨灾</span><span class="input-group-addon" style="padding: 6px 0px; border-right: none;"> </span> <span class="input-group-addon">
											<input type="checkbox" name="jd" id="jd" value="1" onclick="jujdState(this);">
										</span>
									</div-->
								</div>
								<div class="col-lg-6"></div>
							</div>
						</td>
					</tr>
				</table>
			</td>
			<td>
				<table class="table table-condensed  table-responsive table-bordered" style="width: 100%; margin: 0; padding: 0;">
					<tr>
						<td><div class="input-group">
								<span class="input-group-addon addon-text">出险时间</span> <input readonly="readonly" id="cxsj" type="text" class="form-control" placeholder="请选择出险时间"
									value="<%=Times.format("yyyy-MM-dd HH:mm", Times.now())%>"><span class="input-group-addon" onclick="showCalendar()"><i class="glyphicon glyphicon-calendar"></i></span>
							</div></td>
					</tr>
					<tr>
						<td><div class="input-group">
								<span class="input-group-addon addon-text">出险地点</span> <input type="hidden" id="cxdd_"> <input type="hidden" id="cxdd_pca"><input id="cxdd" type="text"
									class="form-control" placeholder="请选择出险地点" onfocus="showMap(1);" readonly="readonly" reg="/^[\w\u4e00-\u9fa5\(\)-]{1,}$/" d-value=""><span
									class="input-group-addon" onclick="showMap(1);"><i class="glyphicon glyphicon-road"></i></span>
							</div></td>
					</tr>
					<tr>
						<td><div class="input-group">
								<span class="input-group-addon addon-text">查勘地点</span> <input type="hidden" id="ckdd_"> <input type="hidden" id="ckdd_pca"> <input id="ckdd" type="text"
									class="form-control" placeholder="请选择查勘地点" onfocus="showMap(2);" readonly="readonly" reg="/^[\w\u4e00-\u9fa5\(\)-]{1,}$/" d-value=""><span
									class="input-group-addon" onclick="showMap(2);"><i class="glyphicon glyphicon-road"></i></span>
							</div></td>
					</tr>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">出险原因</span> <select id="ccyy_selector" onchange="updateCcyy();" class="form-control"><option>选择出险原因</option>
											<optgroup label="-------------------">
												<option>操作不当</option>
												<option>酒后驾驶</option>
												<option>疲劳驾驶</option>
												<option>强行超车</option>
												<option>自然灾害</option>
												<option>天雨路滑</option>
												<option>超速行驶</option>
												<option>超载超限</option>
												<option>机械故障</option>
												<option>巨灾</option>
												<option>其它</option>
											</optgroup></select>
									</div>
								</div>
								<div class="col-lg-6">
									<input id="ccyy_" class="form-control" placeholder="请输入出险原因" disabled="disabled" check="true" reg="/^[\w\u4e00-\u9fa5-,.?:;'!'，。？：；‘！’]{2,}$/" d-value="">
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="row">
								<div class="col-lg-6">
									<div class="input-group">
										<span class="input-group-addon addon-text">出险经过</span> <select id="ccjg_selector" class="form-control" onchange="updateCcjg();"><option>选择出险经过</option>
											<optgroup label="------------------">
												<option>刮擦</option>
												<option>追尾</option>
												<option>互碰</option>
												<option>轮胎单独损坏</option>
												<option>碰撞静物</option>
												<option>自燃</option>
												<option>倾覆</option>
												<option>玻璃单独损坏</option>
												<option>碰撞行人</option>
												<option>车辆盗抢</option>
												<option>其它</option>
											</optgroup></select>
									</div>
								</div>
								<div class="col-lg-6">
									<input id="ccjg_" class="form-control" placeholder="请输入出险经过" disabled="disabled" check="true" reg="/^[\w\u4e00-\u9fa5-,.?:;'!'，。？：；‘！’]{2,}$/" d-value="">
								</div>
							</div>

						</td>
					</tr>
					<tr>
						<td><button class="btn btn-sm btn-primary pull-right" style="width: 125px;" onclick="submitForm(0);">提交</button>
							<button id="force_" disabled="disabled" class="btn btn-sm btn-primary pull-right" style="width: 125px; margin-right: 10px" onclick="submitForm(1);">强制派工</button>
							<button id="end_" disabled="disabled" class="btn btn-sm btn-primary pull-right" style="width: 125px; margin-right: 10px" onclick="CloseWin();">结束报案</button></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td><table class="table table-striped table-bordered table-condensed" style="width: 100%; margin: 0; padding: 0; text-align: left;">
					<caption>今日报案信息</caption>
					<thead>
						<tr>
							<td>报案时间</td>
							<td>报案车辆</td>
							<td>出险地址</td>
							<td>报案详情</td>
						</tr>
					</thead>
					<tbody>
						<it:iterator name="receipt" type="com.acic.jba.bean.Receipt" collection='<%=data.get("receipts")%>'>
							<tr>
								<td>${receipt.reportTimeInfo }</td>
								<td>${receipt.carPlate }</td>
								<td>${fn:substring(receipt.occurAddrInfo , 0, 20)}</td>
								<td style="text-align: center;"><a href="javascript:;" onclick="showReceipt('${receipt.id }')" class='<%= receipt.getId() == 0 ? "hide":""  %>'>查看</a> &nbsp;</td>
							</tr>
						</it:iterator>
						<tr>
							<td colspan="4" class="<%=data.get("receipts")== null || ((List)data.get("receipts")).size() == 0 ? "":"hide"%>">今日暂无报案</td>
						</tr>
					</tbody>
				</table></td>
			<td><table class="table table-striped table-bordered table-condensed table-n-p" style="width: 100%; margin: 0; padding: 0">
					<caption>主要承保险别</caption>
					<tbody style="text-align: left;">
						<tr>
							<td style="padding-left: 9px; width: 30%"><span id="jq_flag" class="badge badge-no">&nbsp;</span>交强险起止时间</td>
							<td style="width: 70%"><div id="jq_s_e" style="display: inline-block;">&nbsp;</div> <a class="pull-right" href="javascript:;" onclick="loadPlys('0330');">历史承保</a></td>
						</tr>
						<tr>
							<td style="padding-left: 9px;"><span id="sy_flag" class="badge badge-no">&nbsp;</span>商业险起止时间</td>
							<td><div id="sy_s_e" style="display: inline-block;"></div> <a class="pull-right" href="javascript:;" onclick="loadPlys('0332');">历史承保</a></td>
						</tr>
						<tr>
							<td><span id="sz_flag" class="badge badge-no">&nbsp;</span>商业三者险</td>
							<td><span id="cs_flag" class="badge badge-no">&nbsp;</span>车损险
								<div class="error-info hide">
									<span class="badge badge-tips">&nbsp;</span>未购车损险,事故责任不在承保范围
								</div></td>
						</tr>
						<tr>
							<td><span id="sj_flag" class="badge badge-no">&nbsp;</span>驾驶员责任险</td>
							<td><span id="zr_flag" class="badge badge-no">&nbsp;</span>自燃险
								<div class="error-info hide">
									<span class="badge badge-tips">&nbsp;</span>未购自燃险,事故责任不在承保范围
								</div></td>
						</tr>
						<tr>
							<td><span id="ck_flag" class="badge badge-no">&nbsp;</span>乘客责任险</td>
							<td><span id="bp_flag" class="badge badge-no">&nbsp;</span>玻璃破碎险
								<div class="error-info hide">
									<span class="badge badge-tips">&nbsp;</span>未购玻璃破碎险,事故责任不在承保范围
								</div></td>
						</tr>
						<tr>
							<td></td>
							<td><span id="dq_flag" class="badge badge-no">&nbsp;</span>全车盗抢险
								<div class="error-info hide">
									<span class="badge badge-tips">&nbsp;</span>未购全车盗抢险,事故责任不在承保范围
								</div></td>
						</tr>
					</tbody>
				</table></td>
		</tr>
	</table>
	<!-- 测试数量:<%=result.getData().get("count")%> -->
	<script type="text/javascript">
		var start = new Date().getTime();
		var start_ = 0;
		var timeUse = 0;
		var timeUseTotal = 0;
		var timeUseMore = 0;
		//提交表单
		var state = true;
		function submitForm(t) {
			state ? realSubmit(t) : $.dialog.tips("内容正在提交,请稍等");
		}

		function realSubmit(t) {
			var d = new Date().getTime();
			if (timeUse == 0) {//如果是首次点击提交 计算提交耗时
				timeUse = d - start;
			}
			if (start_ != 0) {//如果曾经处理过 更多信息 计算更多信息耗时
				timeUseMore = d - start_;
			}
			timeUseTotal = d - start;//计算报案过程全时长
			var flag = true;
			$("input").each(function(i, item) {
				var item_ = $(item);
				var check = item_.attr('check');
				var reg = item_.attr('reg');
				var reg_ = eval(reg);
				var value = item_.val();
				var defaultValue = item_.attr('d-value');
				if (check && !reg_.test(value)) {
					item_.addClass('error');
					item_.val(defaultValue);
				} else {
					item_.removeClass('error');
				}
				if ($(item).attr('class') && $(item).attr('class').indexOf('error') >= 0) {
					flag = false;
				}
			});
			if (!flag) {
				$.dialog.tips("填写的内容存在不正确的项,请先检查");
				return;
			}
			var reporter = $("#reportor").val();
			var reporterNo = $("#reportorNo").val();
			var contact = $("#cont").val();
			var contactNo = $("#contNo").val();
			var carNo = $("#plate").val();
			var involvedCarNum = $("#sacl").val();
			var materialsDestroyFlag = $("#wp").get(0).checked;
			var deadNum = $("#dead").val();
			var injuryNum = $("#injed").val();
			var singleCarFlag = $("#sc").get(0).checked;
			var occurTime = $("#cxsj").val() + ':00';
			var reportTime = new Date().Format("yyyy-MM-dd hh:mm:ss");
			var occurAddr = $("#cxdd").val();
			var ccpca = $("#cxdd_pca").val();
			var occurProvince = ccpca.split(',')[0];
			var occurCity = ccpca.split(',')[1];
			var occurArea = ccpca.split(',')[2];
			var ccjwd = $("#cxdd_").val();
			ccjwd = ccjwd.substring(1, ccjwd.length - 1);
			var occurLngt = ccjwd.split(',')[0];
			var occurLatt = ccjwd.split(',')[1];
			var checkAddr = $("#ckdd").val();
			var ckpca = $("#ckdd_pca").val();
			var checkProvince = ckpca.split(',')[0];
			var checkCity = ckpca.split(',')[1];
			var checkArea = ckpca.split(',')[2];
			var ckjwd = $("#ckdd_").val();
			ckjwd = ckjwd.substring(1, ckjwd.length - 1);
			var checkLngt = ckjwd.split(',')[0];
			var checkLatt = ckjwd.split(',')[1];
			var description = $("#ccjg_").val();
			var reason = $("#ccyy_").val();
			var hugeDisasterFlag = $("#jd").val() == 1;
			var agentClaimFlag = $("#dp").get(0).checked;
			var validTraPlyNo = $("#jqply__").val();
			var validBizPlyNo = $("#syply__").val();
			var carVin = $("#vin").val();
			var carEngine = $("#engine").val();
			var carModel = $("#model").val();
			var availableFlag = getAvailableState(occurTime);
			var operatorId = $("#opt_code").val();
			var recodeCode = $("#r_Uid").val();
			var occurAddressFlag = $("#cxdd_v_flag").val() == 1;
			var checkAddressFlag = $("#ckdd_v_flag").val() == 1;
			var timeOutFlag = $("#timeOutFlag").val() == 1;
			var timeOutReason = $("#timeOutReason").val();
			var timeOutDescription = $("#timeOutDescription").val();
			var dellFlag = t == 1 ? true : getDellFlag(occurTime);
			//组装对象
			var receipt = new Receipt(reporter, reporterNo, contact, contactNo, carNo, involvedCarNum, materialsDestroyFlag, deadNum, injuryNum, singleCarFlag, occurTime,
					reportTime, occurAddr, occurProvince, occurCity, occurArea, occurLngt, occurLatt, checkAddr, checkProvince, checkCity, checkArea, checkLngt, checkLatt,
					description, reason, hugeDisasterFlag, agentClaimFlag, validTraPlyNo, validBizPlyNo, availableFlag, recodeCode, operatorId, timeUse, timeUseTotal, timeUseMore,
					carVin, carEngine, carModel, dellFlag, checkAddressFlag, occurAddressFlag, timeOutFlag, timeOutReason, timeOutDescription);
			/*if (!receipt.validBizPlyNo && !receipt.validTraPlyNo) {
				start_ = new Date().getTime();
				showPopWindow();
				return;
			}*/
			//发送ajax请求
			state = false;
			$.post(getRootPath() + "/submit.ac", {
				receipt : receipt.toString()
			}, function(result) {
				state = true;
				if (result.operationState == 'SUCCESS') {
					result.data.receipt.dellFlag ? showMessage("报案成功,报案号为: " + result.data.receipt.id, 5, 'center').title(false) : showMessage(result.data.receipt.dellStatus, 5,
							'center').title(false);
				} else {
					showMessage(result.data.reason, 5, 'center').title(false);
				}
				setTimeout(function() {
					CloseWin();//提交成功关闭窗口
				}, 5000);
			}, "json");
		}

		//加载历史详情
		function loadPlys(type) {
			var plate = $("#plate").val();
			if (!plate) {
				$.dialog.tips("没有输入车牌号");
			} else {
				$.dialog.tips("正在加载历史承保");
				$.post(getRootPath() + "/loadPlys.ac", {
					type : type,
					plate : plate
				}, function(result) {
					if (result.operationState != "SUCCESS" || result.data.infos.length == 0) {
						$.dialog.tips("没有符合条件的结果");
					} else {
						showPopWindowPlys(result.data.infos);
					}
				}, "json");
			}
		}
		//开启结束报案
		function enableEnd() {
			$("#end_").get(0).disabled = false;
		}
		//切換狀態
		function triggerForce(flag) {
			$("#force_").get(0).disabled = flag;
		}
		//弹出历史承保信息
		function showPopWindowPlys(infos) {
			$.dialog({
				id : "his",
				lockScroll : true,
				drag : false,
				resize : false,
				lock : true,
				title : "承保详情",
				focus : false,
				padding : 0,
				margin : 0,
				max : false,
				min : false,
				width : 600,
				height : 400,
				content : "url:" + getRootPath() + "/static/his.html",
				init : function() {
					var tbody = $(this.content.document.getElementById("tbody"));
					tbody.empty();
					$(infos).each(function(i, item) {
						tbody.append("<tr><td>" + item.PLY_NO + "</td><td>" + item.BEGIN_TIME + "</td><td>" + item.END_TIME + "</td></tr>");
					});
				}
			});
		}
		function replaceCont() {
			var reporter = $("#reportor").val();
			//var cont = $("#cont").val();
			$("#cont").val(reporter);
			/*if (cont.trim().length == 0) {
				不做判断直接联动
			}*/
		}
		function CloseWin() //这个不会提示是否关闭浏览器     
		{
			window.opener = null;
			window.open("", "_self");
			window.close();
		}
		Date.prototype.Format = function(fmt) { //author: meizz 
			var o = {
				"M+" : this.getMonth() + 1, //月份 
				"d+" : this.getDate(), //日 
				"h+" : this.getHours(), //小时 
				"m+" : this.getMinutes(), //分 
				"s+" : this.getSeconds(), //秒 
				"q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
				"S" : this.getMilliseconds()
			//毫秒 
			};
			if (/(y+)/.test(fmt))
				fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
			for ( var k in o)
				if (new RegExp("(" + k + ")").test(fmt))
					fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
			return fmt;
		};
		//打开地图弹窗
		function showMap(t) {
			$.dialog({
				id : "map",
				lockScroll : true,
				drag : false,
				resize : false,
				lock : true,
				title : false,
				focus : false,
				padding : 0,
				margin : 0,
				max : false,
				min : false,
				width : document.body.clientWidth,
				height : window.screen.availHeight - 125,
				content : "url:" + getRootPath() + "/static/gd_map.html",
				init : function() {
					$(this.content.document.getElementById("map_type")).val(t);
					$(this.content.document.getElementById("iCenter")).attr("style", "height: " + (window.screen.availHeight - 185) + "px");
				}
			});
		}
		//保单有效状态判断
		function getAvailableState(occurTime) {
			return occurTime < $("#jq_endTime").val() || occurTime < $("#sy_endTime").val();
		}
		//处置状态
		function getDellFlag(occurTime) {
			var flag = true;
			$(".badge-tips").each(function(i, item) {
				if ($(item).parent().attr('class').indexOf('hide') < 0) {
					flag = false;
				}
			});
			var timeAvailable = occurTime < $("#jq_endTime").val() || occurTime < $("#sy_endTime").val();//过期状态
			return timeAvailable && flag;
		}
		function aa(jq, sy, plate, engine, model, vin) {
			$.dialog.tips("正在加载承保详情");
			$.post(getRootPath() + "/plyInfoByPly.ac", {
				jq : jq,
				sy : sy
			}, plyInfoCallBack, "json");
			$("#plate").val(plate);
			$("#engine").val(engine);
			$("#model").val(model);
			$("#vin").val(vin);
		}
		function showPopWindow() {
			$.dialog({
				id : "pop",
				lockScroll : true,
				drag : true,
				resize : false,
				lock : true,
				title : '更多信息',
				padding : 0,
				margin : 0,
				max : false,
				min : false,
				width : 1000,
				height : window.screen.availHeight - 125,
				content : "url:" + getRootPath() + "/static/more.html"
			});
		}
		function showReceipt(id) {
			$.dialog({
				id : "receipt" + id,
				lockScroll : true,
				drag : false,
				resize : false,
				lock : true,
				title : '报案详情',
				padding : 0,
				margin : 0,
				max : false,
				min : false,
				width : 1000,
				height : window.screen.availHeight - 125,
				content : "url:" + getRootPath() + "/receipt.ac?id=" + id
			});
		}
		//延迟进行数据加载
		function loadPlyInfo_() {
			setTimeout(loadPlyInfo, 200);
		}

		//开启单车事故可选
		function enableSc() {
			$("#sc").get(0).checked = false;
			$("#sc").get(0).disabled = false;
			$("#sc_div").attr('title', '');
		}
		//禁用单车事故可选
		function disableSc() {
			$("#sc").get(0).checked = false;
			$("#sc").get(0).disabled = true;
			$("#sc_div").attr('title', '当前此选项不可选,已由涉案车辆数决定');
		}
		//更新车损险勾选状态
		function updateCsState(dom) {
			//$("#cs").get(0).checked = dom.checked;
			dom.checked && $("#cs_flag").attr('class').indexOf('badge-no') > 0 && $("#sy_s_e").html().trim().length != 0 ? showTips('车损') : hideTips('车损');
		}
		//更新单车事故状态
		function updateSc() {
			var count = $("#sacl").val() == "" ? 0 : $("#sacl").val();
			var wpFlag = $("#wp").get(0).checked;
			var sw = $("#dead").val();
			var ss = $("#injed").val();
			if (count <= 1 && !wpFlag && sw == 0 && ss == 0) {
				enableSc();
			} else {
				disableSc();
			}
		}
		function doNothing() {
		}
		//巨灾&代为求偿互斥
		function jujdState(dom) {
		}

		//更新出险经过
		function updateCcjg() {
			var jg = $("#ccjg_selector").val();
			if (jg.indexOf('其它') >= 0) {
				$("#ccjg_").val("");
				$("#ccjg_").get(0).disabled = false;
			} else if (jg.indexOf('选择出险经过') >= 0) {
				$("#ccjg_").val("");
				$("#ccjg_").get(0).disabled = true;
			} else {
				$("#ccjg_").val(jg);
				$("#ccjg_").get(0).disabled = true;
			}
			var flag = $("#sy_s_e").html().trim().length != 0;
			if (flag) {
				if (jg.indexOf('自燃') >= 0 && $("#zr_flag").attr('class').indexOf('badge-no') > 0) {
					showTips('自燃');
				} else if (jg.indexOf('玻璃单独损坏') >= 0 && $("#bp_flag").attr('class').indexOf('badge-no') > 0) {
					showTips('玻璃');
				} else if (jg.indexOf('车辆盗抢') >= 0 && $("#dq_flag").attr('class').indexOf('badge-no') > 0) {
					showTips('盗抢');
				}
			} else {
				hideTips('自燃');
				hideTips('玻璃');
				hideTips('盗抢');
			}
		}
		function showTips(t) {
			triggerForce(false);
			$(".error-info").each(function(i, item) {
				$(item).html().indexOf(t) >= 0 ? $(item).removeClass("hide") : $(item).addClass("hide");
			});
		}

		function hideTips(t) {
			$("#jq_flag").attr('class').indexOf('badge-no') > 0 || $("#sy_flag").attr('class').indexOf('badge-no') > 0 ? doNothing() : triggerForce(true);
			$(".error-info").each(function(i, item) {
				$(item).html().indexOf(t) >= 0 ? $(item).addClass("hide") : doNothing();
			});
		}
		//更新出险原因
		function updateCcyy() {
			var reason = $("#ccyy_selector").val();
			$("#jd").val(0);
			if (reason.indexOf('其它') >= 0) {
				$("#ccyy_").val("");
				$("#ccyy_").get(0).disabled = false;
			} else if (reason.indexOf('选择出险原因') >= 0) {
				$("#ccyy_").val("");
				$("#ccyy_").get(0).disabled = true;
			} else if (reason.indexOf('巨灾') >= 0) {
				$("#ccyy_").val("");
				$("#ccyy_").get(0).disabled = false;
				$("#jd").val(1);
			} else {
				$("#ccyy_").val(reason);
				$("#ccyy_").get(0).disabled = true;
			}
		}
		function getRootPath() {
			var strFullPath = window.document.location.href;
			var strPath = window.document.location.pathname;
			var pos = strFullPath.indexOf(strPath);
			var prePath = strFullPath.substring(0, pos);
			var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
			return (prePath + postPath);
		}
		function showMessage(info, delay, position) {
			var left = position ? '50%' : '100%';
			var top = position ? '50%' : '100%';
			if (!!delay) {
				delay = 5;
			}
			return $.dialog({
				id : 'msg',
				title : '提示信息',
				content : info,
				width : 200,
				height : 100,
				left : left,
				top : top,
				fixed : true,
				drag : false,
				resize : false,
				time : delay,
				lock : true,
				max : false,
				min : false
			});
		}
		function loadPlyInfo() {
			var palte = $("#plate").val();
			if (!plate) {
				palte = "";
			}
			$.dialog.tips("正在加载承保详情");
			$.post(getRootPath() + "/plyInfo.ac", {
				plate : palte
			}, plyInfoCallBack, "json");
		}
		function plyInfoCallBack(result) {
			if (result.operationState == 'SUCCESS') {
				$(".badge").each(function(i, item) {
					$(item).removeClass('badge-ok').addClass('badge-no');
				});
				var cars = result.data.car ? result.data.car.data : new Array();
				if (cars.length != 0) {
					//TODO更新车辆信息 车牌车价发动机品牌型号
					var car = cars[0];
					$("#engine").val(car.C_CAR_ENGINE);
					$("#model").val(car.C_CAR_MODEL);
					$("#vin").val(car.C_CAR_VIN);
				}
				//更新交强起止时间
				if (result.data.info.jqBegin) {
					$("#jq_s_e").html(result.data.info.jqBegin + '  /  ' + result.data.info.jqEnd);
				} else {
					$("#jq_s_e").html('');
				}
				//更新商业起止时间
				if (result.data.info.syBegin) {
					$("#sy_s_e").html(result.data.info.syBegin + '  /  ' + result.data.info.syEnd);
				} else {
					$("#sy_s_e").html('');
				}
				var ccsj = $("#cxsj").val();
				//更新交强购买状态
				//result.data.info.jqEndTime > new Date().getTime()  判断条件为console.log(result.data.info.jqEnd > ccsj);
				!!result.data.info.jqPly && result.data.info.jqEnd > ccsj ? $("#jq_flag").removeClass('badge-no').addClass('badge-ok') : $("#jq_flag").removeClass('badge-ok')
						.addClass('badge-no');
				$("#jqply__").val(result.data.info.jqPly);
				$("#jq_endTime").val(result.data.info.jqEnd);
				//更新商业险购买状态
				//result.data.info.syEndTime > new Date().getTime()
				!!result.data.info.syPly && result.data.info.syEnd > ccsj ? $("#sy_flag").removeClass('badge-no').addClass('badge-ok') : $("#sy_flag").removeClass('badge-ok')
						.addClass('badge-no');
				$("#syply__").val(result.data.info.syPly);
				$("#sy_endTime").val(result.data.info.syEnd);
				triggerForce(((result.data.info.syEnd > ccsj) || (result.data.infojqEnd > ccsj)));
				if (result.data.info.syEnd > ccsj) {
					for ( var sta in result.data.info.syInfos) {
						updateState(sta, result.data.info.syInfos.sta);
					}
					for ( var sta in result.data.info.syInfos) {
						updateState(sta, result.data.info.syInfos.sta);
					}
				}
				if (!result.data.info.jqPly && !result.data.info.syPly) {
					$("#plate").val().trim().length < 6 ? showPopWindow() : triggerForce(false);
				}
			} else {
				showMessage("获取承保信息失败", 5);
			}
		}
		function updateState(sta, stv) {
			switch (sta) {
			case 'syszx':
				$("#sz_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			case 'sjzwx':
				$("#sj_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			case 'ckzwx':
				$("#ck_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			case 'csx':
				$("#cs_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			case 'qcdqx':
				$("#dq_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			case 'blpsx':
				$("#bp_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			case 'clzrx':
				$("#zr_flag").removeClass('badge-no').addClass('badge-ok');
				break;
			default:
				break;
			}
		}
		function showCalendar() {
			$('#cxsj').datetimepicker("show");
		}
		$('#cxsj').datetimepicker({
			step : 5,
			format : 'Y-m-d H:i',
			maxDate : '+1970/01/01',
			lang : 'ch',
			maxTime : new Date().Format('H:i'),
			onSelectDate : function(r) {
				//判断日期小于今天的话就不做时间的限制,如果大于今天的话就做全部时间限制,如果是今天的话就限制当前时间之后
				var today = new Date();
				today.Format('yyyy-MM-dd') > r.Format('yyyy-MM-dd') ? this.setOptions({
					maxTime : '23:59'
				}) : today.Format('yyyy-MM-dd') == r.Format('yyyy-MM-dd') ? this.setOptions({
					maxTime : today.Format('H:i')
				}) : this.setOptions({
					maxTime : '0:0'
				});
			},
			onSelectTime : function(r) {
				var today = new Date();
				if (today.getTime() - r.getTime() > 48 * 60 * 60 * 1000) {
					$("#timeOutFlag").val(1);
					showTimeOutWindow();
				}
			}
		});
		function showTimeOutWindow() {
			$.dialog({
				id : "timeout",
				lockScroll : true,
				drag : true,
				resize : false,
				lock : true,
				title : '超时报案',
				padding : 0,
				margin : 0,
				max : false,
				min : false,
				width : 425,
				height : 400,
				content : "url:" + getRootPath() + "/static/timeout.html"
			});
		}
		$(function() {
			var mtop = (document.body.scrollHeight - $("#main_table").get(0).clientHeight) / 2;
			$("#sp_div").css({
				'margin-top' : mtop + "px"
			});
			//$("#cxsj").val(new Date().Format("yyyy-MM-dd hh:mm"));//默认出险时间
			//表单验证
			$("input").each(function(i, item) {
				$(item).on('blur', function() {
					var item_ = $(event.currentTarget);
					var check = item_.attr('check');
					var reg = item_.attr('reg');
					var reg_ = eval(reg);
					var value = item_.val();
					var defaultValue = item_.attr('d-value');
					var flag = false;
					if (check && !reg_.test(value)) {
						item_.addClass('error');
						item_.val(defaultValue);
					} else {
						item_.removeClass('error');
						flag = true;
					}
					return flag;
				});
			});
			//自动完成
			$("#plate").autocomplete({
				serviceUrl : getRootPath() + '/queryPlate.ac',
				onSelect : function(suggestion) {
					//获取承保信息
					loadPlyInfo();
				},
				onSearchStart : function(query) {
					query = $('#plate').val().replace("\'", "");
				},
				paramName : 'key'
			});
		});
	</script>
</body>
</html>